package com.zq.多线程设计模式.workerThread设计模式;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

import static java.util.concurrent.ThreadLocalRandom.current;


//  todo 测试不通过
public class WorkerThreadTest {

    public static void main(String[] args) {
        final ProductionChannel channel = new ProductionChannel(5);
        channel.offerProduction(new Production(20));
        AtomicInteger produtionNo = new AtomicInteger();
        IntStream.range(1, 8).forEach(i ->
                new Thread(() -> {
                    while (true){
                        channel.offerProduction(new Production(produtionNo.getAndIncrement()));

                        try {
                            TimeUnit.SECONDS.sleep(current().nextInt(10));
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start()
        );


    }

}
